package com.wnx.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.wnx.db.CollectDao;
import com.wnx.entity.Collect;

public class MycollectAction extends ActionSupport {
	private int gid;
	private int uid;
	private int id;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	private String type;
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public int getGid() {
		return gid;
	}
	public void setGid(int gid) {
		this.gid = gid;
	}
	public int getUid() {
		return uid;
	}
	public void setUid(int uid) {
		this.uid = uid;
	}
	public String execute() {
		if(this.type.equals("del")){
			Collect c = new Collect();
			c.setId(this.id);
			c.setUid(this.uid);
			CollectDao cd = new CollectDao();
			cd.delCollectByid(c);
			List<Collect> collect = cd.selCollectByuid(c);
			if(collect.size()>0){
				HttpServletRequest request = ServletActionContext.getRequest();
				HttpSession session = request.getSession();
				session.setAttribute("collect", collect);
			}
			
			return SUCCESS;
		}else{
		Collect c = new Collect();
		c.setUid(this.uid);
		CollectDao cd = new CollectDao();
		List<Collect> collect = cd.selCollectByuid(c);
		if(collect.size()>0){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		request.setAttribute("collect", collect);
		}
		return SUCCESS;
		}
	}
}
